encrypt using rsa
Type
command
Summary
Encrypt data using the RSA algorithm.
Syntax
encrypt <message> using rsa with {public | private} key <key> [and passphrase <passphrase>] [and padding <padding>]
Description
Use the encrypt using rsa command to encrypt a message using RSA public key encryption.
To encode a message that you only want to be decoded by the holder of the private key, use the form:
encrypt message with public key key
As a signing operation, to encode a message that a receiver can then verify has come from one of the holders of the private key, use the form:
encrypt message with private key key
The optional padding phrase determines the padding mode used when performing the operation. It can be one of:
none
: no padding is done, the application must pad the message appropriatelypkcs1
: PKCS #1 v1.5 padding is used.pkcs1-oaep
: EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty encoding parameter.
If no padding phrase is provided, then the pkcs1
is used.
Note:The pkcs1-oaep
mode is only supported when encrypting with a public key,
trying to use it when encrypting with a private key will return an error.
Important:It is recommended that all new applications use the pkcs1-oaep
padding mode when using public key encryption.
Generating key pairs
Public-private key pairs can be generated using the OpenSSL suite of command-line tools. For example: openssl genrsa -out private_key.pem 512 openssl rsa -pubout -in private_key.pem -out public_key.pem Will generate a key pair of size 512-bits, placing the private key in private_key.pem and the public key in public_key.pem.
For more information on these utilities see https://www.openssl.org/docs/manmaster/man1/rsa.html and https://www.openssl.org/docs/manmaster/man1/genrsa.html.
The maximum length of a message that can be encrypted using RSA is the size of the key in bytes -11. So, for a 512-bit key pair, the maximum encryptable message size is 53 bytes.
For signing, the maximum length of an encryptable message isn't really an issue since typically in that scenario it will be some sort of hash that would be being encrypted. For the more traditional encrypting scenario, however, the standard approach is to use public key cryptography to encrypt a random password which is then used with a symmetric cipher to actually encrypt the payload.
Parameters
Name | Type | Description |
---|---|---|
key | The key to be used for the encryption, in PEM format | |
passphrase | An optional passphrase | |
padding | An optional padding mode | |
message | The message to be encrypted |
Examples
encrypt myMessage using rsa with public key myKey
encrypt thisMessage using rsa with private key privateKey
Related
command: decrypt, encrypt, decrypt using rsa
Compatibility and Support
Introduced
LiveCode 4.6
OS
mac
windows
linux
ios
android
Platforms
desktop
server
mobile